def simple_number(n):
    if n == "":
        return 0
    n = int(n)
    summa = 0
    for i in range(1, n + 1):
        if n % i == 0 and n != 1:
            summa += 1
    if summa <= 2:
        return 1
    return 0


numbers = [x for x in input()]
simple_n = []
for i in range(len(numbers)):
    for j in range(1, len(numbers) + 1):
        if simple_number("".join(numbers[i:j])) == 1:
            simple_n.append(int("".join(numbers[i:j])))
print(0 if len(numbers) != 4 or len(simple_n) == 0 else max(simple_n))
